<?php
function initUrl($url){
	$A = explode("&",$url);
	$result_key = array();
	for($i=0;$i<count($A);$i++){
		$B = explode("=",$A[$i]);
		$result_key[$B[0]] = $A[$i];
	}
	return implode("&",$result_key);
}


function deleteRepeatVar($url,$del_var){
	$two_part = explode("?",$url);
	$A = explode("&",$two_part[1]);
	$result_key = array();
	for($i=0;$i<count($A);$i++){
		$B = explode("=",$A[$i]);
		if($del_var==$B[0]){
			continue;
		}else{
			$result_key[$B[0]] = $A[$i];
		}
	}
	return $two_part[0].'?'.implode("&",$result_key);
}

function uploadimg($tagname,$i){

if ((($_FILES[$tagname]["type"][$i] == "image/gif")
|| ($_FILES[$tagname]["type"][$i] == "image/jpeg")
|| ($_FILES[$tagname]["type"][$i] == "image/png")
|| ($_FILES[$tagname]["type"][$i] == "image/pjpeg"))
&& ($_FILES[$tagname]["size"][$i] < 200000))
  {
  if ($_FILES[$tagname]["error"][$i]> 0)
    {
    echo "错误: " . $_FILES[$tagname]["error"][$i] . "<br />";
    }
  else
    {
    if (file_exists("upload/" . $_FILES[$tagname]["name"][$i]))
      {
      echo $_FILES[$tagname]["name"][$i] . " already exists. ";
      }
    else
      {
       $fname='upload/'.rand(0,10000).time().substr($_FILES['file']['name'][$i],strrpos($_FILES['file']['name'][$i],'.'));//自动命名
       move_uploaded_file($_FILES['file']['tmp_name'][$i],$fname);
      }
    }
  }
else
  {
  echo "文件非法！";
  }

}

function hidePhoneNum($phoneNum){
	if(strlen($phoneNum)>=11){
		return substr($phoneNum,0,3).'****'.substr($phoneNum,7);
	}else{
		return $phoneNum;
	}
}

function time_tran($the_time){
   date_default_timezone_set('PRC');
   $now_time = date("Y-m-d H:i:s");
   $now_time = strtotime($now_time);
   $show_time = strtotime($the_time);
   $dur = $now_time - $show_time;
   if($dur < 60){
    return $dur.'秒前';
   }else{
    if($dur < 3600){
     return floor($dur/60).'分钟前';
    }else{
     if($dur < 86400){
      return floor($dur/3600).'小时前';
     }else{
      if($dur < 259200){//3天内
       return floor($dur/86400).'天前';
      }else{
       //return $the_time;
	   return date('Y-m-d', $show_time);
      }
     }
    }
   }
}

//
function time_tran_time_zone($the_time){
   $now_time = date("Y-m-d H:i:s",time()+8*60*60);
   $now_time = strtotime($now_time);
   $show_time = strtotime($the_time);
   $dur = $now_time - $show_time;
   if($dur < 0){
    return $the_time;
   }else{
    if($dur < 60){
     return $dur.'秒前';
    }else{
     if($dur < 3600){
      return floor($dur/60).'分钟前';
     }else{
      if($dur < 86400){
       return floor($dur/3600).'小时前';
      }else{
       if($dur < 259200){//3天内
        return floor($dur/86400).'天前';
       }else{
        return $the_time;
       }
      }
     }
	}
   }
}
?>
